<template>
  <div class="mod-menu">
    <el-form :inline="true" :model="pamars">
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" row-key="Id" border style="width: 100%; ">
      <el-table-column prop="name" align="center" label="广告位名称" :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column prop="remark" align="center" label="广告位说明" :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column prop="mark_code" align="center" label="广告位置">
        <template slot-scope="scope">
          <!-- 　　　　<div v-if="scope.row.mark_code=='shop-banner'">首页广告图</div>
          　　<div v-if="scope.row.mark_code=='pt-banner'">平台首页广告位</div>
          　　<div v-if="scope.row.mark_code=='pt-banner2'">平台中部首页广告位</div>
          　<div v-if="scope.row.mark_code=='pt-join-us'">平台加入我们广告位</div> -->
          <div v-for="(v, i) in bannerCode" :key="i" v-if="scope.row.mark_code == v.value">{{ v.label }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="ad_location_type" :formatter="adLocationType" align="center" label="广告位类型">
      </el-table-column>

      <!-- <el-table-column prop="owner_type" :formatter="ownerType" align="center" label="渠道">
      </el-table-column> -->
      <el-table-column prop="width,c" align="center" label="宽高">
        <template slot-scope="scope">
          　　　　<div>{{ scope.row.width }}*{{ scope.row.height }}</div>
          　　</template>
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" class="c-error" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pamars.page" :page-sizes="[10, 20, 50, 100]"
      :page-size="pamars.limit" :total="totalPage" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <advertisingPosition-add-update v-if="addOrUpdateVisible" ref="advertisingPositionAddUpdate" @updataList='updataList'></advertisingPosition-add-update>
  </div>
</template>

<script>
import AdvertisingPositionAddUpdate from './advertisingPosition-add-update'
import seviceApi from '@/api/serviceApi.js'
export default {
  data () {
    return {
      pamars: {
        page: 1,
        limit: 10
      },
      totalPage: 0,
      dataList: [],
      dataListLoading: false,
      addOrUpdateVisible: false,
      bannerCode: [
        {
          label: 'APP首页Banner',
          value: 'home-banner',
          type: 0
        },
        {
          label: '创业专区Banner',
          value: 'entrepreneurshipzone-banner',
          type: 0
        },
        {
          label: '公益商城首页Banner',
          value: 'publicshop-banner',
          type: 0
        },
        {
          label: '关于绿马助残公益基金Banner',
          value: 'publicwelfarezone-banner',
          type: 0
        },
        {
          label: '公益讲堂Banner',
          value: 'forum-banner',
          type: 0
        },
        {
          label: '同城商家Banner',
          value: 'localMerchant-banner',
          type: 0
        },
        {
          label: 'app启动广告',
          value: 'startAdvertising',
          type: 0
        },
        {
          label: '资讯轮播图',
          value: 'news-swiper',
          type: 0
        },
        {
          label: '资讯banner图',
          value: 'news-banner',
          type: 0
        }
      ],
    }
  },
  components: {
    AdvertisingPositionAddUpdate
  },
  mounted () {
    this.getList()
  },
  methods: {
    // 更新列表
    updataList (e) {
      if (e == 1) {
        this.getList()
      }
    },
    getList () {
      seviceApi.getAdLocationList(this.pamars).then(res => {
        if (res && res.data.code == 200) {
          this.dataList = res.data.page.list
          this.totalPage = res.data.page.totalCount
        }
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.advertisingPositionAddUpdate.init(id)
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pamars.limit = val
      this.getList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pamars.page = val
      this.getList()
    },
    // ownerType
    adLocationType (row, column) {
      let status = row.ad_location_type
      if (status == 0) {
        return '普通广告位'
      } else {
        return '幻灯广告位'
      }
    },
    // ownerType
    ownerType (row, column) {
      let status = row.owner_type
      if (status == 0) {
        return '平台广告位'
      } else {
        return '商家店铺广告位'
      }
    },
    // 删除
    deleteHandle (id) {
      this.$confirm(`确定要删除该条数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        seviceApi.delAdLocation(id).then(res => {
          if (res && res.data.code == 200) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.getList()
          }
        })
      }).catch(() => { })
    }
  }
}
</script>
